var express = require('express');
var apiProduct = express.Router();
var Mock = require('mockjs');

var _product = {
    'pid': '@guid()',
    'name': '@ctitle(5, 15)',
    'des': '@cparagraph()',
    'price': '@float(100, 800, 3)',
    'marketPrice': '@float(100, 800, 3)',
    'like': '@integer(60, 10000)',
    'isFav': '@boolean',
    'pic': '@image("600x400", "@color", "#fff", "png", "17fe.cn")'
}

var _comment = {
        'commentId': '@guid()',
        'title': '@ctitle(10, 25)',
        'createDate': '@date("yyyy-MM-dd HH:mm:ss")',
        'content': '@cparagraph()',
        'agree': '@integer(60, 10000)',
        'disapproval': '@integer(0, 100)',
        'user': {
            'userId': '@guid()',
            'userName': '@last',
            'logo': '@image("80x80", "@color", "#fff", "png", "17fe")'
        }
    }
    //产品详情
apiProduct.get('/category/:id', function(request, response, next) {
    var id = request.param('id');
    var data = Mock.mock({ 'array|10': [_product] });
    response.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8' });
    var responseData = data.array;

    // console.log(JSON.stringify(responseData));
    response.end(JSON.stringify(responseData));
});


apiProduct.get('/detail/:id', function(request, response, next) {
    var id = request.param('id');
    var data = Mock.mock({ _product });
    response.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8' });
    var responseData = data._product;
    // console.log(JSON.stringify(responseData));
    response.end(JSON.stringify(responseData));
});

//产品评论
apiProduct.get('/comment/list', function(request, response, next) {
    var id = request.param('id');
    var data = Mock.mock({ 'array|10': [_comment] });
    response.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8' });
    var responseData = data.array;

    // console.log(JSON.stringify(responseData));
    response.end(JSON.stringify(responseData));
});

module.exports = apiProduct;
